package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.pojo.Linkman;
import com.kaishengit.pojo.Linkrecord;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;

@Service
@Transactional
public class LinkmanService extends BaseService {

	public void save(Linkman linkman, User user, Project project) {
		if (linkman == null || user == null || project == null) {
			return;
		}
		linkman.setUser(user);
		linkman.setProject(project);
		getLinkmanDao().saveOrUpdate(linkman);
	}

	public List<Linkman> getlinkmans(Project project) {
		return getLinkmanDao().findByProject(project);

	}

	public Linkman getlinkman(int id) {
		return getLinkmanDao().findById(id);
	}

	public void delete(int id) {
		List<Linkrecord> records = getLinkRecordDao().findByLinkman(
				getLinkmanDao().findById(id));
		for (Linkrecord record : records) {
			getLinkRecordDao().del(record.getId());
		
		}
		getLinkmanDao().del(id);

	}

}
